package com.ctgu.算法.快速幂;

import com.sun.org.apache.regexp.internal.RE;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Scanner;

/**
 * @author: Backdiy
 * @data: 2021/4/17 21:03
 * @desc:
 */
public class 快速幂板子 {
    static Scanner scanner = new Scanner(System.in);

    /*
    防止高精度下，乘法会溢出的情况
     */
    static class 快速乘 {
        public static void main(String[] args) {
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            System.out.println(multi(n, m));
        }
        static int multi(int n,int m){
            int ans = 0;
            while (m>0){
                if ((m&1)==1){
                    ans=ans+n;
                }
                m>>=1;
                n*=2;
            }
            return ans;
        }
    }

    static class 普通快速幂 {
        public static void main(String[] args) {
            int n =scanner.nextInt();
            int m =scanner.nextInt();
            System.out.println(pow2(n, m));
        }

        static int pow2(int n, int m) {
            int ans =1;
            while (m>0){
                if ((m&1)==1) ans=ans*n;
                m>>=1;
                n*=n;
            }
            return ans;
        }
    }

}
